package com.hx.er.action.admin.rest;

import org.springframework.beans.factory.annotation.Autowired;

import com.hx.er.action.base.ErAdminAction;
import com.hx.er.bean.base.RestraurantBean;
import com.hx.er.bean.base.UserBean;
import com.hx.er.common.system.ErRestraurant;
import com.hx.er.service.admin.IAdminRestService;

public class AdminRestReviveAction extends ErAdminAction {
	// 序列化ID
	private static final long serialVersionUID = -1127474451530316813L;

	private long restId;
	private RestraurantBean restBean;
	private String updateUserNickName;

	@Autowired
	private IAdminRestService adminRestService;

	public String init() {
		this.initPage();
		return SUCCESS;
	}

	public String revive() {
		if (this.restBean == null) {
			this.restBean = new RestraurantBean();
		}
		
		this.restBean.setRestId(this.restId);
		this.restBean.setUpdateUserId(super.getUserInfoLogin().getUserId());

		int count = this.adminRestService.reviveRest(this.restBean);

		if (count == 0) {
			this.initPage();
			this.addActionError(super.getText(REVIVE_FAILURE_MSG));
			return INPUT;
		} else {
			// 缓存中加入该餐厅
			ErRestraurant.addRest(this.restBean);
			this.addActionMessage(super.getText(REVIVE_SUCCESS_MSG));
			return SUCCESS;
		}
	}

	private void initPage() {
		// 查询餐馆信息
		this.restBean = this.adminRestService.getRestById(this.restId);
		// 最后更新人查询
		UserBean userBean = this.adminRestService.getUserAliveById(this.restBean.getUpdateUserId());
		this.updateUserNickName = userBean.getNickName();
	}

	public long getRestId() {
		return restId;
	}

	public void setRestId(long restId) {
		this.restId = restId;
	}

	public RestraurantBean getRestBean() {
		return restBean;
	}

	public void setRestBean(RestraurantBean restBean) {
		this.restBean = restBean;
	}

	public String getUpdateUserNickName() {
		return updateUserNickName;
	}

	public void setUpdateUserNickName(String updateUserNickName) {
		this.updateUserNickName = updateUserNickName;
	}

}
